package com.huaxia.day9;

import java.net.URL;
import java.net.URLClassLoader;

public class ClassLoadTest {

    public static void main(String[] args) throws Exception  {
        ClassLoader loader = ClassLoader.getSystemClassLoader();//获取系统类加载器
        Class objClass = loader.loadClass("com.huaxia.day9.ClassLoadA");//加载A
        System.out.println("after load ClassLoadA");
        System.out.println("before init ClassLoadA");
        objClass = Class.forName("com.huaxia.day9.ClassLoadA");//初始化A


        // UrlClassLoader 本地加载类 ， 还可以网上下载类
        URLClassLoader classLoader = new URLClassLoader(new URL[]{new URL("https://gitee.com/yelvjiashu/huaxia/attach_files/Sample.class")});
        Class remoteClass = classLoader.loadClass("com.huaxia.day9.Sample");
        Object obj = remoteClass.newInstance();
    }
}
